﻿using IBLL;
using IDAL;
using Models;

namespace BLL
{
    /// <summary>
    /// 会员操作具体实现
    /// </summary>
    public class MemberBLL : IMemberBLL
    {
        /// <summary>
        /// 面向接口开发
        /// 面向规则开发
        /// </summary>
        /// <param name="memberDAL"></param>
        public MemberBLL(IBaseDAL<Member> memberDAL )
        {
            MemberDAL = memberDAL;
        }

        public IBaseDAL<Member> MemberDAL { get; }

        public async Task<int> AddMember(Member member)
        {
            return await MemberDAL.AddAsync(member);
        }

        public async Task<int> DeleteMember(int id)
        {
            //先查，再删除
            var m = MemberDAL.GetAllAsync().FirstOrDefault(x => x.Id == id);
             return await MemberDAL.DeleteAsync(m);
        }

        public List<Member> GetAllMembers()
        {
            return MemberDAL.GetAllAsync().ToList(); ;
        }

        public async Task<int> UpdateMember(Member member)
        {
            return await MemberDAL.UpdateAsync(member);
        }
    }
}
